<template>
  <el-dialog v-el-drag-dialog title="删除费用" :visible.sync="visible" width="500px" @closed="reset">
    <div class="deletePage">
      <h3>请选择要删除的费用</h3>
      <p>
        <el-checkbox
          v-model="form.free0"
          false-label=""
          true-label="1"
        >远距配送费</el-checkbox>
        <el-checkbox
          v-model="form.free1"
          false-label=""
          true-label="1"
        >上楼费</el-checkbox>
        <el-checkbox
          v-model="form.free2"
          false-label=""
          true-label="1"
        >服务费</el-checkbox>
        <el-checkbox
          v-model="form.free3"
          false-label=""
          true-label="1"
        >租赁费</el-checkbox>
      </p>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button @click="visible = false">
        关闭
      </el-button>
      <el-button :loading="$loadingPlugin.success" type="primary" @click="success">
        保存
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { deleteGoodsAllPrice } from '@/api'

  export default {
    name: 'distributionDialog',
    data() {
      return {
        visible: false,
        org: null,
        temp: {
        },
        form: {

        }
      }
    },
    methods: {
      open(temp, org) {
        this.org = org
        return new Promise(resolve => {
          this.resolve = resolve
          this.visible = true
          if (temp) {
            this.temp = Object.assign(this.temp, temp)
          }
        })
      },
      async success() {
        let del = 0
        const form = this.form
        const orgId = this.org.orgId
        const goodsId = this.temp.goodsId
        if (form.free0) {
          del += 1
        }
        if (form.free1) {
          del += 2
        }
        if (form.free2) {
          del += 4
        }
        if (form.free3) {
          del += 8
        }
        const delInfo = 70
        await deleteGoodsAllPrice({ del, orgId, goodsId, delInfo })
        this.resolve()
        this.visible = false
        this.$notify({
          title: '提示',
          message: '操作成功',
          type: 'success',
          duration: 2000
        })
      },
      reset() {
        this.form = {
          free0: '',
          free1: '',
          free2: '',
          free3: ''
        }
      }
    }
  }
</script>

<style lang="scss" scoped>
.deletePage {
  min-height: 100px;
  text-align: center;
}
</style>
